<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <%--<link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/css/H-ui.min.css">--%>
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/css/H-ui.admin.css">
    <link rel="stylesheet" href="${ctx}/libjs/plugins/h-ui/style.css">
    <script type="text/javascript" src="${ctx}/libjs/plugins/bootstrap/js/bootstrap-select.js"></script>
    <link rel="stylesheet" type="text/css" href="${ctx}/libjs/plugins/bootstrap/css/bootstrap-select.css">
    <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
    <%--<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>--%>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>

<%--    <script type="text/javascript"--%>
<%--            src="https://webapi.amap.com/maps?v=1.3&key=e392de55be62b195115e32b97043a1bd&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>--%>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=d8f0f46fc7446a9bed5a28cdc5aaeb52&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
    <script type="text/javascript" src="${ctx}/appjs/elec/elecStation.js"></script>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>设备管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>新增站点</strong>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a href="javascript:window.history.back()"><i class="fa fa-times"></i> 返回</a>' +
            '</li>' +
            '</ol>';
    });
</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">新增站点</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="frmElecStation">
                       <%-- <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">运营开通时间：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="operateStartTime" name="operateStartTime">
                            </div>
                        </div>--%>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">充电站名称：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="stationName" name="stationName">
                            </div>
                        </div>

                        <<%--div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">所属公司：</label>
                            <div class="col-sm-8">
                                <select name="tenantCompanyId" id="tenantCompanyId" class="form-control">
                                    <c:forEach items="${tenantCompanyInfos}" var="tenantCompanyInfo">
                                        <option value="${tenantCompanyInfo.tenantCompanyId}">${tenantCompanyInfo.companyName}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
--%>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">站点类型：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="bizType" id="bizType">
                                    <option value="0">自营</option>
                                    <option value="1">加盟</option>
                                </select>
                            </div>
                        </div>
                       <div class="form-group row">
                           <label class="col-sm-3 col-form-label text-right">所属加盟商：</label>
                           <div class="col-sm-8">
                               <select id="operatorId" name="operatorId" class="form-control" placeholder="所属加盟商">
                                   <option value="" selected="selected">请选择</option>
                                   <c:forEach items="${operators}" var="bean">
                                       <option value="${bean.operatorId}">${bean.operatorName}
                                       </option>
                                   </c:forEach>
                               </select>
                           </div>
                       </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">省-市-区：</label>
                            <div class="col-sm-2">
                                <select name="provinceId" id="provinceId"
                                        class="form-control chosen-select"
                                        style="width: 100%" onchange="station.getCity()">
                                    <option value="" selected="selected">--请选择--</option>
                                    <c:forEach items="${provinces}" var="province">
                                        <option value="${province.provinceId}">${province.provinceName}</option>
                                    </c:forEach>
                                </select>
                            </div>

                            <div class="col-sm-2">
                                <select name="cityId" id="cityId"
                                        class="form-control chosen-select"
                                        style="width: 100%" onchange="station.getArea()">
                                    <option value="" selected="selected">${pileGroup.joinCity.city}</option>
                                </select>
                            </div>

                            <div class="col-sm-2">
                                <select id="areaId" name="areaId" class="form-control" placeholder="市区">
                                    <option value="" selected="selected">${pileGroup.joinArea.area}</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">地址详情：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="address" name="address">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">纬度：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="latitude" name="latitude">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">经度：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="longitude" name="longitude">
                            </div>
                        </div>
                        <div class="form-group row">
                           <label class="col-sm-3 col-form-label text-right">地图：</label>
                           <div class="col-sm-8">
                               <button type="button" class="btn btn-info" onclick="showMap()">开启地图</button>
                           </div>
                           <%--<div></div>--%>
                           <%--<button id="id_get_data" type="button" class="btn btn-success">获取当前位置数据</button>--%>
                        </div>
                       <div class="form-group row">
                           <label class="col-sm-3 col-form-label text-right">站点状态：</label>
                           <div class="col-sm-8">
                               <select class="form-control" name="stationStaus" id="stationStaus">
                                   <option value="">请选择</option>
                                   <option value="1">正常</option>
                                   <option value="0">停用</option>
                               </select>
                           </div>
                       </div>
                       <div class="form-group row">
                           <label class="col-sm-3 col-form-label text-right">投运时间：</label>
                           <div class="col-sm-8">
                               <input type="text" class="form-control" id="operateStartTime" name="operateStartTime">
                           </div>
                       </div>
                       <%--<div class="form-group row">
                           <label class="col-sm-3 col-form-label text-right">标签：</label>
                           <div class="col-sm-8">
                               <select multip id="labelId" name="labelId" class="form-control" placeholder="" multiple="multiple" >
                                   <option value="" selected="selected">请选择</option>
                                   <c:forEach items="${label}" var="bean">
                                       <option value="${bean.labelId}">${bean.labelName}
                                       </option>
                                   </c:forEach>
                               </select>
                           </div>
                       </div>--%>
                       <div class="form-group row istam">
                           <label class="col-sm-3 col-form-label text-right">多选标签：</label>
                           <select id="labelIds" name="labelIds" class="selectpicker bla bla bli" multiple data-live-search="true" title="请选择">
                               <c:forEach items="${label}" var="bean">
                               <option value="${bean.labelId}">${bean.labelName}
                               </option>
                               </c:forEach>
                           </select>
                       </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">备注说明：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="stationRemark" name="stationRemark">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片1：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <img id="stationImg1" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file1" name="file1"/>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片2：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <img id="stationImg2" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file2" name="file2"/>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片3：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <img id="stationImg3" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file3" name="file3"/>
                                    <input hidden name="stationImg3">
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片4：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <img id="stationImg4" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file4" name="file4"/>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">图片5：</label>
                            <div class="col-sm-8">
                                <div id="">
                                    <img id="stationImg5" src="${ctx}/statics/img/upload-img.png"
                                         style="position: relative" width="155px" height="120px">
                                    <input type="file" id="file5" name="file5"/>
                                </div>
                                <span>图片尺寸建议为：<span class="text-danger">98px*75px</span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-3 col-sm-offset-8 text-right">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade modal1" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modalBox" style="height: 80%;width: 100%">
        <div class="modal-content" style="height: 100%">
            <div class="modal-header">
                <%--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">--%>
                <%--&times;--%>
                <%--</button>--%>
                <h4 class="modal-title" id="myModalLabel">
                    请点击地图选择坐标
                </h4>
            </div>
            <div class="modal-body" style="height: 80%">
                <div id="containerMap"></div>
                <div id="myPageTop">
                    <table>
                        <tr>
                            <td>
                                <label>按关键字搜索：</label>
                            </td>
                            <td class="column2">
                                <label>左击获取经纬度：</label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="text" style="color: #000" placeholder="请输入关键字进行搜索" id="tipinput">
                            </td>
                            <td class="column2">
                                <input type="text" readonly="true" id="lnglat">
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" id="confirmMap">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script type="text/javascript">
    // /*地图选择经纬度*/
    // var p = $("#id_address_input").AMapPositionPicker();
    // $("#id_get_data").on('click', function () {
    //     var s = JSON.stringify(p.AMapPositionPicker('position'));
    //     var parse = JSON.parse(s);
    //     var longitude = parse.longitude;
    //     var latitude = parse.latitude;
    //     $("#longitude").val(longitude)
    //     $("#latitude").val(latitude)
    // });

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        var bizStartTime = laydate.render({
            elem: '#bizStartTime',
            type: 'time',
            format: 'HH:mm:ss',
            trigger: 'click'
        });

        var bizEndTime = laydate.render({
            elem: '#bizEndTime',
            type: 'time',
            format: 'HH:mm:ss',
            trigger: 'click'
        });

        var operateStartTime = laydate.render({
            elem: '#operateStartTime',
            type: 'date',
            format: 'yyyy-MM-dd',
            trigger: 'click'
        });
    });


    /**************************/

    $("#file1").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg1").attr("src", objUrl);
        }
    });

    $("#file2").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg2").attr("src", objUrl);
        }
    });

    $("#file3").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg3").attr("src", objUrl);
        }
    });

    $("#file4").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg4").attr("src", objUrl);
        }
    });

    $("#file5").change(function () {
        var objUrl = getObjectURL(this.files[0]);//获取文件信息
        var fileSize = $(this)[0].files[0].size
        if (objUrl) {
            if (fileSize > (2 * 1024 * 1024)) {
                layer.msg('请上传小于2M的图片！');
                $(this).val("");
                return
            }
            $("#stationImg5").attr("src", objUrl);
        }
    });

    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) {
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }

    $(window).on('load', function () {
        $('.selectpicker').selectpicker({
            'selectedText': 'cat'
        });
        // $('.selectpicker').selectpicker('hide');
    });


</script>

</body>
</html>

<script>
    //地图
    function showMap() {
        $('#myModal').modal('show')
        var map = new AMap.Map("containerMap", {
            resizeEnable: true,
            zoom: 11,
        });
        map.plugin(["AMap.ToolBar"], function () {
            map.addControl(new AMap.ToolBar());
        });
        if (location.href.indexOf('&guide=1') !== -1) {
            map.setStatus({scrollWheel: false})
        }
        //为地图注册click事件获取鼠标点击出的经纬度坐标
        var clickEventListener = map.on('click', function (e) {
            document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
            $('#lnglat').attr({
                'data-longitude': e.lnglat.getLng(),
                'data-latitude': e.lnglat.getLat()
            })
        });
        var auto = new AMap.Autocomplete({
            input: "tipinput"
        });
        var placeSearch = new AMap.PlaceSearch({
            map: map
        });  //构造地点查询类
        AMap.event.addListener(auto, "select", select);//注册监听，当选中某条记录时会触发
        function select(e) {
            if (e.poi && e.poi.location) {
                map.setZoom(15);
                map.setCenter(e.poi.location);
            }
            placeSearch.setCity(e.poi.adcode);
            placeSearch.search(e.poi.name);
        }


    }

    $('#myModal').on('click', '#confirmMap', function () {
        var longitude = $('#lnglat').attr('data-longitude');
        var latitude = $('#lnglat').attr('data-latitude');
        if (!longitude && !latitude) {
            layer.msg('请点击地图选择经纬度！');
            return
        }
        $('#longitude').val(longitude);
        $('#latitude').val(latitude);
        $('#myModal').modal('hide')
    });


</script>
<script>
    addElecStation.init();
</script>
